﻿using LitJson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace SkillSystem
{
    /// <summary>
    /// 技能接收器
    /// </summary>
    public class SkillReceiverBase : ISkillReceiver
    {
        ISkillReceiver reallyReceiver;

        public SkillReceiverBase(ISkillReceiver reallyReceiver=null)
        {
            this.reallyReceiver = reallyReceiver;
        }

        public void ReceiverSkillItem(SkillItem skillItem)
        {
            Debug.Log("This Obj Get Skill !It's Id is " + skillItem.CurSkillItemData.ID);
            if (skillItem.DamageArgs[SkillDefines.ArgArray].IsArray)
            {
                IList<JsonData> datas = skillItem.DamageArgs[SkillDefines.ArgArray].inst_array;
                for (int i = 0; i < datas.Count; i++)
                {
                    DamageResultType retultType = (DamageResultType)datas[i][SkillDefines.ResultType].AsInt;
                    IDamageResultSolver solover= SkillSystemFacade.Inst.GetDamageResultSolver(retultType);
                    if (solover!=null)
                    {
                        solover.SolveData(reallyReceiver != null ? reallyReceiver : this, datas[i]);
                    }
                    else
                    {
                        DebugUtils.LogError(retultType +"  未注册");
                    }
                }
            }
        }
    }
}
